package fragmentson;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.wq.cycling.R;

import activity.SonActivity;
import fragmentson.backhandle.BackHandledFragment;


/**
 * 设备详情
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */
public class AddCar_A extends BackHandledFragment {

	private View rootView;
	private EditText et_edittext1,et_edittext2,et_edittext3,et_edittext4,et_edittext5;
	private TextView tv_textview1,tv_textview2,tv_textview3,tv_textview4;
	//店铺id  品牌id   物业id  民警id  厂商id
	private String shopid="",brandid="";

    @Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_addcar_a, null);
		initView();
		return rootView;
	}

	private void initView() {
		// TODO Auto-generated method stub
		((TextView) rootView.findViewById(R.id.tv_title)).setText(R.string.add_car);
		et_edittext1 = ((EditText) rootView.findViewById(R.id.et_edittext1));
		et_edittext2 = ((EditText) rootView.findViewById(R.id.et_edittext2));
		et_edittext3 = ((EditText) rootView.findViewById(R.id.et_edittext3));
		et_edittext4 = ((EditText) rootView.findViewById(R.id.et_edittext4));
		et_edittext5 = ((EditText) rootView.findViewById(R.id.et_edittext5));
		tv_textview1 = ((TextView) rootView.findViewById(R.id.tv_textview1));
		tv_textview2 = ((TextView) rootView.findViewById(R.id.tv_textview2));
		tv_textview3 = ((TextView) rootView.findViewById(R.id.tv_textview3));
		tv_textview4 = ((TextView) rootView.findViewById(R.id.tv_textview4));
		rootView.findViewById(R.id.ll_linear1).setOnClickListener(listener);
		rootView.findViewById(R.id.ll_linear2).setOnClickListener(listener);
		rootView.findViewById(R.id.ll_linear3).setOnClickListener(listener);
		rootView.findViewById(R.id.ll_linear4).setOnClickListener(listener);
		rootView.findViewById(R.id.tv_next).setOnClickListener(listener);

	}


	public static AddCar_A newInstance() {
		AddCar_A fragment = new AddCar_A();
		return fragment;
	}

	private View.OnClickListener listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()){
				case R.id.tv_modify:
					break;
				case R.id.ll_linear1:
					((SonActivity) getActivity()).addFragment(DeviceProperty.newInstance(new DeviceProperty.CallBackListener() {
						@Override
						public void listener(String item,String id) {
							shopid = id;
							tv_textview1.setText(item);
						}
					},"1",""),true);
					break;
				case R.id.ll_linear2:
					((SonActivity) getActivity()).addFragment(DeviceProperty.newInstance(new DeviceProperty.CallBackListener() {
						@Override
						public void listener(String item,String id) {
							brandid = id;
							tv_textview2.setText(item);
						}
					},"2",""),true);
					break;
				case R.id.ll_linear3:
					if(brandid.isEmpty()){
						Toast.makeText(getActivity(),"请先选择品牌",Toast.LENGTH_LONG).show();
						return;
					}
					((SonActivity) getActivity()).addFragment(DeviceProperty.newInstance(new DeviceProperty.CallBackListener() {
						@Override
						public void listener(String item,String id) {
							tv_textview3.setText(item);
						}
					},"3",brandid),true);
					break;
				case R.id.ll_linear4:
					if(brandid.isEmpty()){
						Toast.makeText(getActivity(),"请先选择品牌",Toast.LENGTH_LONG).show();
						return;
					}
					((SonActivity) getActivity()).addFragment(DeviceProperty.newInstance(new DeviceProperty.CallBackListener() {
						@Override
						public void listener(String item,String id) {
							tv_textview4.setText(item);
						}
					},"4",brandid),true);
					break;
				case R.id.tv_next:
					((SonActivity) getActivity()).addFragment(AddCar_B.newInstance(et_edittext1.getText().toString(),et_edittext2.getText().toString(),shopid,brandid,tv_textview3.getText().toString()+"",tv_textview4.getText().toString()+"",et_edittext3.getText().toString(),et_edittext4.getText().toString(),et_edittext5.getText().toString()));
					break;
				default:
					break;
			}
		}
	};

	@Override
	public boolean onBackPressed() {
		return false;
	}

}
